/**
 * Created by yangfan on 2016/11/24.
 */
/**
 * Created by yangfan on 2016/11/22.
 */
define(['config/appregister',
    "i18n",
    "business/myResume/services/httpServices",
    "business/services/utils",
    "business/services/filter",
    "business/services/regionService"],function(app,i18n,httpServices,utils){
    app.controller('myResumePreviewCtrl', function($scope,$state,$filter,$stateParams,$rootScope,setUrl) {
        $scope.i18n = i18n;
        $scope.$parent.isMyResume = false;
        $scope.personSrc = "them/images/resume-person-pic.png";
        $scope.infoFill = [
            {title:"基本资料",logoSrc:"them/images/resume-baseInfo-pic.png",isFill:false},
            {title:"求职意向",logoSrc:"them/images/resume-airplain-pic.png",isFill:false},
            {title:"工作经验",logoSrc:"them/images/resume-expericence-pic.png",isFill:false},
            {title:"教育经历",logoSrc:"them/images/resume-eduexpericence-pic.png",isFill:false},
            {title:"项目经验",logoSrc:"them/images/resume-projectexpreience-pic.png",isFill:false},
            {title:"站内作品",logoSrc:"them/images/resume-netinnerwork-pic.png",isFill:false}
        ];
    function getLeftView(){
        $scope.personInfo = [
            {src:"them/images/compImages/preview-marjor.png",title:"专业:",value:$scope.allData.edueList[0]===undefined ?'':$scope.allData.edueList[0].profe.pdcName},
            {src:"them/images/compImages/preview-region.png",title:"现居住地:",value:utils.getPlace($scope.basicInfo.lregionObject)},
            {src:"them/images/compImages/preview-cellphone.png",title:"手机:",value:$scope.basicInfo.phone},
            {src:"them/images/compImages/preview-email.png",title:"邮箱:",value:$scope.basicInfo.email},
            {src:"them/images/compImages/preview-box.png",title:"工作经验:",value:$scope.basicInfo.workYear + "年"},
            {src:"them/images/compImages/preview-condition.png",title:"求职状态:",value:$scope.basicInfo.jobStatus.dictName},
            {src:"them/images/compImages/preview-condition.png",title:"语言:",value:utils.getDoubleLan($scope.basicInfo.language)},
            {src:"them/images/compImages/preview-condition.png",title:"婚姻状态:",value:$filter("getMarital")($scope.basicInfo.maritalStatus)},
            {src:"them/images/compImages/preview-condition.png",title:"政治面貌:",value:$scope.basicInfo.politicalStatusObjec.dictName},
            {src:"them/images/compImages/preview-condition.png",title:"户口所在地:",value:$filter("getPlace")($scope.basicInfo.htObject)},
        ];
    }

        $scope.validate = {
            "IDCard":"/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/",
            "number":"/^\d{3}$/",

        };


        $scope.jumpToBlogXq = function(state,para){
            if(!state){
                return
            }
            var url = $state.href(state,para);
            window.open(setUrl.getUrl(url),'_blank');

        };


        //获取简历信息
        function  get(userId){
            var req = {
                type:"GET",
                uri:"get",
                data:{
                    userId:userId
                }
            };
            httpServices.getCvdatabases(req).success(function(response){
                var data = response.data;
                $scope.$apply(function(){
                	$scope.logoUrl = response.data.logoUrl;
                    //基本信息
                    $scope.allData = response.data ;
                    $scope.basicInfo  = {
                        name:data.name,
                        sex:data.sex,
                        birthday:data.birthday,
                        //开始工作年份
                        jobTime:data.jobTime,
                        workYear:data.workYear,
                        phone:data.phone,
                        //
                        jobStatus:data.jobStatusObject,
                        email:data.email,

                        //现居住地 传市级单位
                        lregionObject:{
                            region:data.lregionObject,
                            area:data.lareaObject,
                        },
                        //户口所在地
                        htObject:{
                            provice:data.htprovinceObject,
                            region:data.htregionObject,
                            area:data.htareaObject
                        },
                        //婚姻状态
                        maritalStatus:data.maritalStatus,
                        //证件号
                        card:{
                            cardId:data.cardId,
                            cardNumber:data.cardNumber
                        },
                        //政治面貌
                        politicalStatusObjec:data.politicalStatusObject,
                        language:data.clList,
                        //详细居住地址
                        expectWorkPlace:data.expectWorkPlace,
                        introduction:data.introduction,
                    };
                    getLeftView();

                    //求职意向
                    $scope.jobIntention = {
                        salary:data.jobIntentionVo.salaryObject,
                        //职能
                        jobConf:data.jobIntentionVo.cvdFdcList,
                        //到岗时间
                        jobInArrivalTime:data.jobIntentionVo.arrivalTime,
                        //行业
                        jobInIndustryConf:data.jobIntentionVo.cvdGuildList,
                        //工作性质
                        jobNature:data.jobIntentionVo.dc,
                        //期望工作地
                        jobInRegionIntension:data.jobIntentionVo.cvdEwpAddressList
                    };



                    //工作经历
                    if(data.workList.length == 0){
                        //show 新增工作经验
                    }else {
                        var arrWorkExpression = [],obj;
                        data.workList.forEach(function(item,index,array){
                            obj = {
                                weId:item.weId,
                                cvdId:item.cvdId,
                                startValue:item.startTime,
                                endValue:item.endTime,
                                companyName:item.companyName,
                                //行业
                                workExpreIndustryConf:item.dc,
                                //规模
                                companyScale:item.scale,

                                //职能
                                funcd:item.funcd,
                                //公司性质
                                jobDc:item.natureDc,
                                //工作性质
                                jobNature:item.jobDc,

                                // 部门
                                department:item.department,
                                //薪资水平
                                salary:item.salaryObject,
                                introduction:item.introduction
                            };
                            arrWorkExpression.push(obj);
                        });
                        $scope.workExpression = arrWorkExpression;
                        if($scope.workExpression.length == 0){
                            $scope.isInitAddNew.workExpression = true;
                        }
                    }

                    //教育经历
                    if(data.edueList.length == 0){
                        //show 新增教育经历
                    }else {
                        var arrEdu = [],obj;
                        data.edueList.forEach(function(item,index,array){
                            obj = {
                                cvdId:item.cvdId,
                                eeId:item.eeId,
                                startValue:item.startTime,
                                endValue:item.endTime,
                                school:item.eduName,
                                majorConf:item.profe,
                                overseas:item.overseas,
                                introduction:item.introduction
                            };
                            arrEdu.push(obj);
                        })
                        $scope.educationExpression = arrEdu;
                    }

                    //项目经验
                    if(data.peList.length == 0){
                        //show 新增项目经验
                    }else {
                        var arrProject = [],obj;
                        data.peList.forEach(function(item,index,array){
                            obj = {
                                cvdId:item.cvdId,
                                peId:item.peId,
                                companyName:item.companyName,
                                startValue:item.startTime,
                                endValue:item.endTime,
                                peName:item.peName,
                                roleName:item.roleName,
                                introduction:item.introduction
                            };
                            arrProject.push(obj);
                        });
                        $scope.projectExpression = arrProject;
                    }


                });

            }).error(function(response){})

        }
        if(!angular.isUndefined($stateParams.userId)){
            $scope.userId = $stateParams.userId;
            get($scope.userId) ;
        }
        $scope.goPersonsMainPage = function(){
                if(!!$rootScope.userLoginInfo.logged && $rootScope.userLoginInfo.data.userId == $scope.userId){
                    $state.go('myMainPage',{userId:$scope.userId});
                }else{
                    $state.go('othersMainPage',{userId:$scope.userId})
                }


        };

		//获取发表博文
		function  getBlogList(){
            var req = {
                type:"GET",
                uri:"getBlogListByUserId",
                data:{
                    type:2,
                    pageNo:1,
                    pageSize:10,
                    userId:$scope.userId
                }
            };
            httpServices.userServices(req).success(function(response){
                $scope.$apply(function(){
                	console.log(response.data.list)
                	$scope.blogList = response.data.list;
                })
            });
        };
		getBlogList();

    })
});